﻿using System;

using ExplorerGame.Gameboard;
using ExplorerGame.Gameboard.Elements;

namespace ExplorerGame.Gameboard
{
    internal class GameboardGenerator
    {
        private Random random = new Random();

        internal Gameboard Generate(int width, int height)
        {
            var gameboard = new Gameboard(width, height);

            for (int widthIndexer = 0; widthIndexer < width; widthIndexer++)
            {
                for (int heightIndexer = 0; heightIndexer < height; heightIndexer++)
                {
                    var gameboardElement = GetRandomGameboardElement();
                    gameboard.SetElementAt(widthIndexer, heightIndexer, gameboardElement);
                }
            }

            //Location startingHeroLocation = new Location { Width = random.Next(width), Height = random.Next(height) };
            Location startingHeroLocation = new Location { Width = 1, Height = 1 };

            gameboard.HeroLocation = startingHeroLocation;

            return gameboard;
        }

        private GameboardElement GetRandomGameboardElement()
        {
            int random = this.random.Next(20);

            if (random >= 19)
            {
                return new GameboardElementLake();
            }
            else if (random >= 16)
            {
                return new GameboardElementHills();
            }
            else if (random >= 10)
            {
                return new GameboardElementForest();
            }
            else 
            {
                return new GameboardElementPlains();
            }
        }
    }
}
